<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>03猜数字</title>
</head>

<body>
    <button onclick="alert('警告信息')">测试警告框</button>
    <button onclick="confirm('您确定要关闭吗?')">测试确认框</button>
    <button onclick="prompt('请输入你的设备码')">测试输入框</button>
    <hr>
    <h4>已生成一个1~100之间的随机数:</h4><br>
    <input type="text" placeholder="请输入数字" id="num">
    <button onclick="check()">点我验证</button><br>
    <h4>小提示:<span></span></h4>

    <script>
        // 生成随机数
        let r = parseInt(Math.random() * 100) + 1;
        let temp = 0;
        console.log('打个小抄:' + r);
        // let spanE = document.querySelector('span');
        function check() {
            let num = document.getElementById('num').value;
            //4.判断是否为非数字，如果是非数字，直接结束函数
            if (isNaN(num)){
                alert('请输入数字');
                retuen;
            }
            let spanE = document.querySelector('span');
            if (num < r) {
                temp++;
                spanE.innerHTML = '猜小了!';
            }
            if (num > r) {
                temp++;
                spanE.innerHTML = '猜大了';
            }
            if (num == r) {
                temp++;
                spanE.innerHTML = '恭喜你用了' + temp + '次就猜对了!';
            }
        }
    </script>
</body>

</html>